package com.niit.dao.impl;

import java.util.List;

import com.niit.bean.Contacts;
import com.niit.bean.User;
import com.niit.dao.ContactsDao;
import com.niit.utils.DbUtil;

public class ContactsDaoImpl implements ContactsDao {

	private DbUtil util=new DbUtil();
	@Override
	public int add(Contacts t) {
		String sql = "insert into tb_contacts(username,contact) values(?,?) ";
		int a=util.update(sql, t.getUsername(),t.getContact());
		return a;
	}

	@Override
	public int delete(Contacts t) {
		String sql="delete from tb_contacts where id=? ";
		int a=util.update(sql, t.getId());
		return a;
	}

	@Override
	public int update(Contacts t) {
		String sql="update tb_contacts set username=?,contact=? ";
		int a=util.update(sql, t.getUsername(),t.getContact());
		return a;
	}

	@Override
	public List<Contacts> findAll(int start, int end) {
		return null;
	}

	@Override
	public int findTotal() {
		String sql = "select count(*) from tb_contacts where username = ?";
		int count = util.selectCount(sql);
		return count;
	}

	@Override
	public List<Contacts> findContacts(User user, int start, int end) {
		String sql="select * from (select rownum r,tb_contacts.* from tb_contacts where username = ?) a where a.r>? and a.r<=? ";
		List<Contacts> list=util.select(sql, Contacts.class,user.getUsername(), start,end);
		return list;
	}

}
